<html>
<head><meta charset='utf-8'/><title><%=title%></title>

</head>
<body>
	<%- message %>
	<form >
		<p><input type='text' placeholder='用户名' id='username'/></p>
		<p><input type='password' placeholder='密码' id='psw1' name='psw1'/></p>
		<p><input type='password' placeholder='重复密码' id='psw2' name='psw2'/></p>
		<p><button type='button' id='register'>确认</button></p>
		<p><button type='button' id='login'>登录</button></p>
	</form>
	<script type="text/javascript" src="javascripts/jquery.min.js"></script>
	<script type="text/javascript" >
		$(function(){
			
			$('#login').click(function(){
				location.href='login';
			})

			$('#register').click(function(){
				
				var username=$('#username').val();
				var psw1=$('#psw1').val();
				var psw2=$('#psw2').val();
				var data={'name':username,'psw':psw1};
				console.log(data);
				if(!username||psw1!==psw2){
					
					$('body').prepend('<div style="color:red;">用户名不能为空或密码不一致</div>');
				}
				else {
					
					$.ajax({
						url:'/register',
						type:'post',
						data:data,
						success:function(data,status){
							if(status=='success'){
								location.href='login';

							}
						},
						error:function(data,err){
							console.log('ajax fail');
							location.href='register';
						}

					})
					
				}
			})
		});
	</script>
</body>
</html>